﻿import QtQuick 2.15
import QtQuick.Controls 2.15
import QtGraphicalEffects 1.15

Item {    
    width: screenWidth
    height: screenHeight

    Item{
        id:backGround
        anchors.fill: parent
    }

    property string linkState: Cpp_Connect.modbusState ? "已连接" : "未连接"



    Image {         // 背景图片
        id: backImg
        anchors.fill: backGround

        source: "qrc:/Images/loginBackGround.jpg"

        MouseArea{
            anchors.fill: parent
            enabled: !linkSettingWindow.visible
            acceptedButtons: Qt.LeftButton
            onClicked: {
                if(linkState === "已连接")
                {
                    loginWindow.visible = false
                    automaticPanel.visible = true
                    Cpp_Connect.setQmlPage(1);
                }
            }
        }

        Rectangle{
            id:hidenArea_link
            width: screenWidth / 2
            height: 450
            color: "transparent"
            // color: "red"
            anchors.bottom:parent.bottom
            anchors.left: parent.left

            MouseArea{
                anchors.fill: parent                
                pressAndHoldInterval: 1000
                onPressAndHold: {
                    console.log("显示隐藏区域 -- 连接属性")
                    linkSettingWindow.visible  = !linkSettingWindow.visible
                }
            }
        }
        Rectangle{
            id:hidenArea_Title
            width: screenWidth / 2
            height: 450
            color: "transparent"
            // color: "green"
            anchors.bottom:parent.bottom
            anchors.right: parent.right

            MouseArea{
                anchors.fill: parent
                pressAndHoldInterval: 1000
                onPressAndHold: {
                    console.log("显示隐藏区域 -- 标题设置")

                }
            }
        }
    }

    Rectangle{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 40
        color: "transparent"
        border.width: 1
        width: 200
        height: 80

        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            font.bold: true
            color: "red"
            text:linkState
        }
    }



    Rectangle{              // 退出按钮
        id:exitBtn
        width: 120
        height: 60
        border.width: 1
        radius: 10
        anchors.right: backGround.right
        anchors.rightMargin: 30
        anchors.top: backGround.top
        anchors.topMargin: 30

        Image {
            id: exitBtnImg
            width: 30
            height: 30
            anchors.left: exitBtn.left
            anchors.leftMargin: 5
            anchors.verticalCenter: exitBtn.verticalCenter
            source: "qrc:/Images/logout_Icon.png"
        }

        ColorOverlay{
            source: exitBtnImg
            anchors.fill: exitBtnImg
            color: "black"
        }

        Text{
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            text:"  退出"
        }

        MouseArea{
            anchors.fill: parent
            onClicked: {
                Qt.quit()
            }
        }
    }


    Text {          // 标题
        id: logWindowTitle
        anchors.top: backGround.top
        anchors.topMargin: 200
        anchors.horizontalCenter: backGround.horizontalCenter
        font.pixelSize: 150
        color: "white"
        text: qsTr("11轴复合机" + '\n' + " 控制系统")
    }

    Component.onCompleted: {
        dateShow_Text.text = Qt.formatDateTime(new Date(), "yyyy-MM-dd")
        timeShow_Text.text = Qt.formatDateTime(new Date(), "hh:mm:ss")
    }

    Timer{
        interval: 1000
        running: true
        repeat: true

        onTriggered: {
            dateShow_Text.text = Qt.formatDateTime(new Date(), "yyyy-MM-dd")
            timeShow_Text.text = Qt.formatDateTime(new Date(), "hh:mm:ss")
        }
    }


    Text{
        id:timeShow_Text
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.bottom: backGround.bottom
        anchors.bottomMargin:  250
        font.pixelSize: 60
        color: "black"
    }

    Text{
        id:dateShow_Text
        anchors.bottom: timeShow_Text.top
        anchors.bottomMargin: 50
        anchors.horizontalCenter: backGround.horizontalCenter
        font.pixelSize: 80
    }

    Text{
        id:vertionDescription
        anchors.right: backGround.right
        anchors.rightMargin: 30
        anchors.bottom: backGround.bottom
        anchors.bottomMargin: 30
        font.pixelSize: 50
        color: "white"
        font.bold: true
        text: "V " + Cpp_Connect.Version_Description
    }

    // 连接参数设置界面
    LinkParameterSettingWindow{
        id:linkSettingWindow
        visible: false
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 200
    }







}
